from app import create_app, db
from app.models import User
from config import Config

app = create_app()
app.config['SQLALCHEMY_DATABASE_URI'] = Config.SQLALCHEMY_DATABASE_URI

with app.app_context():
    # 需要手动创建创建数据库

    # 创建数据库表
    db.create_all()

    # 添加测试数据
    if not User.query.first():
        # 添加测试用户
        user = User(username='admin', role='admin',
                    password='$2b$12$38pW/KZWaliAIBwzWGI8f.4WSBTK4ppBhPU8ytaElGlYYCXIRPiaC')
        db.session.add(user)

        db.session.commit()
        print('Database initialized with test data')
    else:
        print('Database already contains data')